package com.android.GernerateKeySet;

import java.io.File;
import java.util.Vector;


import android.content.SharedPreferences;
import android.os.Environment;

public class PreferenceInfo {
	private String Certfile = "NULL";
	private String PVfile = "NULL";

	Vector<String> mFileName;
	private SharedPreferences.Editor ed;
	public PreferenceInfo(SharedPreferences sharedPref){
		String ext = Environment.getExternalStorageState();
		String path = null;
		mFileName = new Vector<String>();
		ed = sharedPref.edit();
		String certnm = sharedPref.getString("Cert", "NULL");
		
		
		if(ext.equals(Environment.MEDIA_MOUNTED)){
			path = Environment.getExternalStorageDirectory().getAbsolutePath() +"/cert/";
		}else{
			path = Environment.MEDIA_MOUNTED;			
		}
		File files = new File(path);
		if(files.listFiles(new JavaFilter())== null){

			setCertfile("NULL");
			setPVfile("NULL");
		}
		else if(files.listFiles(new JavaFilter()).length>0)
		{
			boolean file_exist = false;
			for(File file : files.listFiles(new JavaFilter())){
				if(file.getName().equals(certnm)){
					file_exist = true;
					break;
				}
			}
			if(file_exist){
				setCertfile(certnm);
				setPVfile("PV"+certnm.substring(0,certnm.length()-4));
			}else{
				setCertfile("NULL");
				setPVfile("NULL");
			}
				
		}
	}
	public void setCertfile(String filename){
		Certfile = filename;
		ed.putString("Cert", Certfile);
		ed.commit();
	}
	public void setPVfile(String filename){
		PVfile = filename;
	}
	
	public String getCertfile(){
		return Certfile;		
	}
	public String getPVfile(){
		return PVfile;
		
	}
}
